package jp.tkym.labs.m3d;

import jp.tkym.labs.geom.CoordinateModel;
import jp.tkym.labs.geom.Vector3f;

public class Translator3D{
	ProjectionTranslator projection;
	DeviceTranslator device;
	private CoordinateModel viewCoodinateModel;
	private CoordinateModel localCoodinateModel;
	
	Translator3D(
			CoordinateModel viewCoodinateModel, 
			ProjectionTranslator projection,
			DeviceTranslator device){
		this.projection = projection;
		this.device = device;
		this.viewCoodinateModel = viewCoodinateModel;
	}
	
	public Translator3D local(CoordinateModel localCoodinateModel){
		this.localCoodinateModel = localCoodinateModel;
		return this;
	}
	
	public Vector3f translate(Vector3f point){
		Vector3f view = localCoodinateModel.onView(viewCoodinateModel).translate(point);
		Vector3f proj = this.projection.translate(view);
		return this.device.translate(proj);
	}
	
	public class Matrix_2_3{
		public final float m00, m01, m02, m10, m11, m12;
		private Matrix_2_3(
				float m00, float m01, float m02, 
				float m10, float m11, float m12){
			this.m00 = m00;
			this.m01 = m01;
			this.m02 = m02;
			this.m10 = m10;
			this.m11 = m11;
			this.m12 = m12;
		};
	}
	
	public Matrix_2_3 affineTransform(){
		Vector3f d_x = translate(new Vector3f(1.0f, 0.0f, 0.0f));
		Vector3f d_y = translate(new Vector3f(0.0f, 1.0f, 0.0f));
		Vector3f d_0 = translate(new Vector3f(0.0f, 0.0f, 0.0f));
		return new Matrix_2_3(
						d_x.x - d_0.x,
						d_y.x - d_0.x,
						d_0.x,
						d_x.y - d_0.y,
						d_y.y - d_0.y,
						d_0.y
						);
	}
	// public AffineTransform getAffineTransform(String id){
	// CoodinateComposite co = getComposite(id);
	// if(co != null){
	// Vector3D m_x = new Vector3D(1,0,0);
	// Vector3D m_y = new Vector3D(0,1,0);
	// Vector3D m_0 = new Vector3D(0,0,0);
	// Vector3D w_x = co.translateWorldCoordinate(m_x);
	// Vector3D w_y = co.translateWorldCoordinate(m_y);
	// Vector3D w_0 = co.translateWorldCoordinate(m_0);
	// Vector3D v = viewPosition();
	// Vector3D d_x = transform(w_x, v);
	// Vector3D d_y = transform(w_y, v);
	// Vector3D d_0 = transform(w_0, v);
	// double m00 = d_x.x - d_0.x;
	// double m01 = d_y.x - d_0.x;
	// double m02 = d_0.x;
	// double m10 = d_x.y - d_0.y;
	// double m11 = d_y.y - d_0.y;
	// double m12 = d_0.y;
	// return new AffineTransform(m00, m10, m01, m11, m02, m12);
	// }else{
	// return null;
	// }
	// }
}